package com.gxa.www.cl.controller;

import com.gxa.www.cl.common.base.RespResult;
import com.gxa.www.cl.service.DrugService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class DrugController {

    @Autowired
    private DrugService drugService;
    @GetMapping("/drug/show")
    public RespResult<List<Map<String, Object>>> getDrugs() {
        return RespResult.success("成功返回", drugService.getDrugs());
    }
    @PostMapping("/drug/del")
    public RespResult deleteDrugs(@RequestParam(value= "id")  Integer id) {
        try {
            drugService.deleteDrug(id);
            Map<String, Object> response = new HashMap<>();
            response.put("code", 0);
            response.put("message", "药品删除成功");
            return RespResult.success(response);
        } catch (Exception e) {
            Map<String, Object> response = new HashMap<>();
            response.put("code", 1);
            response.put("message", "药品删除失败");
            return RespResult.error(response.toString());
        }
    }
//    @PostMapping("/add")
//    public int addDrug(@RequestBody Map<String, Object> formData) {
//        try {
//            return drugDTO.addDrug(formData);
//        } catch (Exception e) {
//            // 记录异常日志
//            logger.error("Error adding drug: {}", formData, e);
//            // 返回错误码
//            return -1;
//        }
//    }
}
